import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("SingleChildScrollView Demo"),
        actions: [IconButton(onPressed: () {}, icon: Icon(Icons.share))],
      ),
      body: DialogViewDemo(),
    );
  }
}

// Cupertino : iOS风格的UI

class DialogViewDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Widget dialogBox;
    //判断机型系统是 iOS 或者 安卓
    if (Platform.isIOS) {
      dialogBox = _iosAlertView();
    } else {
      dialogBox = _androidDialogView();
    }
    return Column(
      children: [dialogBox],
    );
  }

  Widget _androidDialogView() {
    return AlertDialog(
      title: Text("友情提示"),
      content: Text("确定要删除吗"),
      actions: [
        TextButton(
            onPressed: () {
              print("取消操作");
            },
            child: Text("取消")),
        TextButton(
            onPressed: () {
              print("确认操作");
            },
            child: Text("确认")),
      ],
    );
  }

  Widget _iosAlertView() {
    return CupertinoAlertDialog(
      title: Text("友情提示"),
      content: Text("确定要删除吗"),
      actions: [
        CupertinoDialogAction(
          child: Text("取消"),
          onPressed: () {
            print("取消操作");
          },
        ),
        CupertinoDialogAction(
          child: Text("确认"),
          onPressed: () {
            print("确认操作");
          },
        )
      ],
    );
  }
}
